package org.goodsmanager.controller;

import jakarta.servlet.http.HttpSession;
import org.goodsmanager.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class IndexController {

    @GetMapping("/")
    public String index(HttpSession session) {
        // 检查用户是否已登录
        User currentUser = (User) session.getAttribute("currentUser");
        if (currentUser == null) {
            // 未登录，重定向到登录页面
            return "redirect:/auth/login";
        }
        // 已登录，重定向到仪表盘
        return "redirect:/dashboard";
    }

    @GetMapping("/doc")
    public String apiDoc() {
        return "doc/api";
    }
}